home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / crobots7 / chaser.r next >
Text File  |  1988-07-21  |  2KB  |  51 lines

  1. /* Chaser */
  2. /* By Eric Maddox (Origional idea by Dan Manty) */
  3. /* finds enemy then moves twards him while fireing */
  4. main()
  5. {int direction, /* suspected direction to enemy */
  6.      y,         /* direction + 10 */
  7.      range,     /* distance to enemy */
  8.      dam,       /* damage taken so far */
  9.      ctr;       /* delay counter */
  10. direction=0;
  11. dam=0;
  12. y=10;
  13. range=0;
  14. ctr=0;
  15. while (1)
  16. {
  17.  while (scan(direction+5,5)==0)                      /* find aprox. position */
  18.       {
  19.        direction=direction+10;
  20.        if ((direction>355) || (direction<5) || damage() > dam)
  21.          {                                   /* if damage is being taken or */
  22.           drive (rand(360),100);   /* if he wasn't found in that sweep move */
  23.           while (ctr < 10)                                         /* delay */
  24.                ++ctr;
  25.           ctr=0;
  26.           drive (0,0);                                              /* stop */
  27.          }
  28.        dam=damage();
  29.        if (direction>359)
  30.          direction=direction-360;
  31.       }
  32.  y=direction+10;
  33.  while ((scan(direction,1)==0) && (direction < y))
  34.       direction=direction+1;             /* Locate exact direction to enemy */
  35.  while (scan(direction,1)>0)
  36.       {                                        /* fire as often as possible */
  37.        range=scan(direction,1);                      /* find range to enemy */
  38.        if (range > 1)
  39.          {
  40.           if (range < 707) cannon(direction,range);                 /* Fire */
  41.           if (range > 100) drive (direction,50);             /* move closer */
  42.           if (range < 100) drive (direction,0);     /* do not get too close */
  43.          }                                                            /* if */
  44.       }
  45.  drive (direction,0);                              /* when we lost him stop */
  46.  if (scan(direction,2)==0)
  47.    direction=y-10;                           /* if we lost him search again */
  48. }                                                   /* end of infinite loop */
  49. }                                                                   /* main */
  50.  
  51.